package com.running.mobile;

import java.util.Map;

import javax.servlet.http.HttpSession;

import com.isomorphic.datasource.DataSource;
import com.isomorphic.datasource.DataSourceManager;

/**
 * 
 * 修改密码
 * @author Administrator
 *
 */
public class ChangePasswordDMI {
	@SuppressWarnings({ "rawtypes" })
	public void update(Map record, HttpSession session)throws Exception
	{
		//获得当前用户pk
		Map currUser = (Map) session.getAttribute("currUser");
		Object userPK =  currUser.get("pk");
		
		//确认旧密码是否正确
		DataSource userDS = DataSourceManager.getDataSource("user");
		Map user = userDS.fetchById(userPK);
		String oldPW = (String) user.get("password");
		if(!oldPW.equals(record.get("oldPassword"))){
			throw new RuntimeException("旧密码错误");
		}
		
		//更新密码
		 userDS.update(user, record);
	}


}
